package o;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.base.bean.AppInfoBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appgallery.wishlist.api.RealizedWishInfo;
import com.huawei.appgallery.wishlist.api.ShortWishListResBean;
import com.huawei.appgallery.wishlist.api.WishInfo;
import com.huawei.appgallery.wishlist.api.WishListResBean;
import com.huawei.appgallery.wishlist.bean.WishDeleteResBean;
import com.huawei.appgallery.wishlist.bean.WishDetail;
import com.huawei.appgallery.wishlist.bean.WishDetailResBean;
import com.huawei.appgallery.wishlist.bean.WishInfoListCache;
import com.huawei.appgallery.wishlist.bean.WishInfoListCache.WishInfoCache;
import com.huawei.appgallery.wishlist.ui.activity.WishAddActivityProtocol;
import com.huawei.appgallery.wishlist.ui.activity.WishCreateActivity;
import com.huawei.appgallery.wishlist.ui.activity.WishDetailActivity;
import com.huawei.appgallery.wishlist.ui.activity.WishDetailActivityProtocol;
import com.huawei.appgallery.wishlist.ui.activity.WishDetailActivityProtocol.Request;
import com.huawei.appgallery.wishlist.ui.activity.WishListDeleteActivity;
import com.huawei.appgallery.wishlist.ui.cardkit.bean.WishBaseInfoCardBean;
import com.huawei.appgallery.wishlist.ui.cardkit.bean.WishNoAppCardBean;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishAppsNode;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishBaseInfoNode;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishEmptyNode;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishEmptyNodeV2;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishNoAppNode;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishNotFoundNode;
import com.huawei.appgallery.wishlist.ui.cardkit.node.WishNotFoundNodeV2;
import com.huawei.appgallery.wishlist.ui.fragment.WishAddFragment;
import com.huawei.appgallery.wishlist.ui.fragment.WishDetailFragment;
import com.huawei.appgallery.wishlist.ui.fragment.WishListDeleteFragment;
import com.huawei.appgallery.wishlist.ui.fragment.WishListFragment;
import com.huawei.hmf.annotation.ApiDefine;
import com.huawei.hmf.annotation.Singleton;
import java.util.List;
import java.util.Map.Entry;
import o.dce.j;
import org.json.JSONException;
import org.json.JSONObject;

@ApiDefine(uri = dck.class)
@Singleton
public class dcx implements dck {

    static class d implements IServerCallBack {
        private d() {
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            if (responseBean instanceof dcf) {
                dcf o_dcf = (dcf) responseBean;
                if (o_dcf.getResponseCode() != 0) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(j.ˋ));
                } else if (o_dcf.getRtnCode_() == 0) {
                    new dcp().ॱ();
                } else if (50101 == o_dcf.getRtnCode_()) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(j.ˈ));
                    new dcp().ॱ();
                } else if (50103 == o_dcf.getRtnCode_()) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(j.ˋˊ));
                } else if (50104 == o_dcf.getRtnCode_()) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(j.ˊᐝ));
                } else {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(j.ˊ));
                }
            }
        }
    }

    public dcx() {
        ᐝ();
    }

    private void ᐝ() {
        dbp o_dbp = (dbp) fho.ˏ().ˋ("WishBase").ॱ(dbp.class);
        o_dbp.ॱ("wish4emptycard", WishEmptyNode.class, ddc.class);
        o_dbp.ॱ("wish4notfoundcard", WishNotFoundNode.class, ddd.class);
        o_dbp.ॱ("wish4emptycard2", WishEmptyNodeV2.class, dde.class);
        o_dbp.ॱ("wish4notfoundcard2", WishNotFoundNodeV2.class, ddf.class);
        o_dbp.ॱ("wishappscard", WishAppsNode.class, dcy.class);
        o_dbp.ॱ("wishnoappcard", WishNoAppNode.class, WishNoAppCardBean.class);
        o_dbp.ॱ("wishbaseinfocard", WishBaseInfoNode.class, WishBaseInfoCardBean.class);
        cfw.ˊ(dcg.APIMETHOD, dcf.class);
        cfw.ˊ(dcq.APIMETHOD, WishListResBean.class);
        cfw.ˊ(dco.APIMETHOD, WishDetailResBean.class);
        cfw.ˊ(dcu.APIMETHOD, dcs.class);
        cfw.ˊ(dcr.APIMETHOD, WishDeleteResBean.class);
        cfw.ˊ(dci.APIMETHOD, ShortWishListResBean.class);
        o_dbp.ˎ("create.wish.activity", WishCreateActivity.class);
        o_dbp.ˋ("wish.list.fragment", WishListFragment.class);
        o_dbp.ˎ("wish.detail.activity", WishDetailActivity.class);
        o_dbp.ˋ("wish.add.fragment", WishAddFragment.class);
        o_dbp.ˋ("wish.delete.list.fragment", WishListDeleteFragment.class);
        cjl.ˎ("delete.wish.activity", WishListDeleteActivity.class);
        cjl.ˋ("wish.detail.fragment", WishDetailFragment.class);
    }

    public void ˊ() {
        String str = "";
        for (Entry entry : WishInfoListCache.ˊ().ˏ().entrySet()) {
            String str2;
            WishInfoCache wishInfoCache = (WishInfoCache) entry.getValue();
            if (!TextUtils.isEmpty(wishInfoCache.ˋ())) {
                PackageInfo ᐝ = ((cdg) cdb.ॱ(cdg.class)).ᐝ(wishInfoCache.ˋ());
                if (ᐝ != null && ᐝ.versionCode >= wishInfoCache.ॱ()) {
                    str2 = (String) entry.getKey();
                    String str3 = str + str2 + ",";
                    dch.ˎ.ˋ("WishListImpl", "app:" + wishInfoCache.ˋ() + " has installed.feedback to store:" + str2);
                    ddb.ˎ().ॱ(str2);
                    WishInfoListCache.ˊ().ˊ(str2, false);
                    str2 = str3;
                    str = str2;
                }
            }
            str2 = str;
            str = str2;
        }
        if (str.endsWith(",")) {
            Object substring = str.substring(0, str.length() - ",".length());
        }
        if (!TextUtils.isEmpty(substring)) {
            WishInfoListCache.ˊ().ॱ();
            ResponseBean ॱ = cfw.ॱ(new dcu(substring));
            if (ॱ.getResponseCode() == 0 && ॱ.getRtnCode_() == 0) {
                dch.ˎ.ˋ("WishListImpl", "feedback to store success");
            } else {
                dch.ˎ.ˊ("WishListImpl", "feedback to store failed." + ॱ.getResponseCode() + "-" + ॱ.getRtnCode_());
            }
        }
    }

    public Boolean ˋ(String str, String str2, int i) {
        if (TextUtils.isEmpty(str)) {
            dch.ˎ.ˋ("WishListImpl", "error task,can not find wish Id.");
            return Boolean.valueOf(false);
        }
        ResponseBean ॱ = cfw.ॱ(new dco(str));
        if (ॱ instanceof WishDetailResBean) {
            WishDetailResBean wishDetailResBean = (WishDetailResBean) ॱ;
            if (wishDetailResBean.getResponseCode() == 0 && wishDetailResBean.getRtnCode_() == 0) {
                WishDetail ˎ = wishDetailResBean.ˎ();
                if (ˋ(ˎ)) {
                    AppInfoBean appInfoBean = (AppInfoBean) ˎ.ʽ().get(0);
                    if (appInfoBean != null && str2.equals(appInfoBean.ˏॱ()) && String.valueOf(i).equals(appInfoBean.ʻ())) {
                        return Boolean.valueOf(true);
                    }
                    dch.ˎ.ˋ("WishListImpl", "app Info bean error.");
                } else {
                    dch.ˎ.ˋ("WishListImpl", "wishDetail error,no detail or no AppInfoList");
                }
            } else {
                dch.ˎ.ˋ("WishListImpl", "wishDetail response error:" + ॱ.getResponseCode() + ",rtnCode:" + ॱ.getRtnCode_());
            }
        }
        return Boolean.valueOf(false);
    }

    private boolean ˋ(WishDetail wishDetail) {
        if (wishDetail == null || wishDetail.ˋ() != 5 || wishDetail.ʼ() != 1 || wishDetail.ʽ() == null || wishDetail.ʽ().size() <= 0) {
            return false;
        }
        return true;
    }

    public cjm ˏ(Context context, RealizedWishInfo realizedWishInfo) {
        if (realizedWishInfo == null) {
            return null;
        }
        dch.ˎ.ˋ("WishListImpl", "WISH app installed:" + realizedWishInfo.ᐝ());
        cjo wishDetailActivityProtocol = new WishDetailActivityProtocol();
        Request request = new Request();
        request.ˋ(realizedWishInfo.ॱʼ());
        request.ˊ(realizedWishInfo.ॱʻ());
        request.ˎ(realizedWishInfo.ᐧ());
        wishDetailActivityProtocol.ˋ(request);
        return new cjm("wish.detail.activity", wishDetailActivityProtocol);
    }

    public void ॱ() {
        eud.ˊ(new RealizedWishInfo());
    }

    public void ˋ() {
        dda.ˏ();
    }

    public void ˏ(boolean z) {
        WishInfoListCache.ˊ().ˎ(z);
    }

    public void ˎ() {
        ddb.ˎ().ॱ();
    }

    public List<RealizedWishInfo> ˏ() {
        return ddb.ˎ().ˋ();
    }

    public boolean ˎ(String str, int i) {
        List ˋ = ddb.ˎ().ˋ(str);
        return ˋ.size() <= 0 || ((RealizedWishInfo) ˋ.get(0)).ʿ() != i;
    }

    public String ˋ(String str) {
        ddb.ˎ().ˎ(str);
        String ˎ = WishInfoListCache.ˊ().ˎ(str);
        WishInfoListCache.ˊ().ˎ(str, true);
        return ˎ;
    }

    public void ˏ(Context context, String str, int i) {
        if (UserSession.getInstance().isLoginSuccessful()) {
            String str2;
            if (i == 10) {
                str2 = "0";
            } else if (i == 13) {
                str2 = "3";
            } else {
                str2 = "1";
            }
            cfw.ˎ(new dcg(str, str2, 0), new d());
            return;
        }
        ˊ(context, str, i);
    }

    private void ˊ(final Context context, final String str, final int i) {
        eoj.ˋ().ˎ("WishListImpl", new AccountBussinessListener(this) {
            final /* synthetic */ dcx ˎ;

            public void onAccountBusinessResult(ccp o_ccp) {
                if (102 == o_ccp.ˎ) {
                    new Handler(Looper.getMainLooper()).post(new Runnable(this) {
                        final /* synthetic */ AnonymousClass3 ˊ;

                        {
                            this.ˊ = r1;
                        }

                        public void run() {
                            this.ˊ.ˎ.ˏ(context, str, i);
                            eoj.ˋ().ˊ("WishListImpl");
                        }
                    });
                } else {
                    eoj.ˋ().ˊ("WishListImpl");
                }
            }
        });
        eod.ॱ(context);
    }

    public int ʻ() {
        return ddk.ˊ();
    }

    public void ˎ(String str) {
        if (!TextUtils.isEmpty(str)) {
            try {
                JSONObject jSONObject = new JSONObject(str);
                WishInfo wishInfo = new WishInfo();
                wishInfo.fromJson(jSONObject);
                WishInfoListCache.ˊ().ˎ(wishInfo.ˏ(), wishInfo.ˊ(), "", 0, wishInfo.ʼ(), true);
            } catch (JSONException e) {
                dch.ˎ.ˋ("WishListImpl", "msgBody json error JSONException");
            } catch (IllegalArgumentException e2) {
                dch.ˎ.ˋ("WishListImpl", "msgBody json error IllegalArgumentException");
            } catch (IllegalAccessException e3) {
                dch.ˎ.ˋ("WishListImpl", "msgBody json error IllegalArgumentException");
            } catch (InstantiationException e4) {
                dch.ˎ.ˋ("WishListImpl", "msgBody json error IllegalArgumentException");
            } catch (ClassNotFoundException e5) {
                dch.ˎ.ˋ("WishListImpl", "msgBody json error IllegalArgumentException");
            }
        }
    }

    public cjm ˏ(String str, int i) {
        cjo wishAddActivityProtocol = new WishAddActivityProtocol();
        WishAddActivityProtocol.Request request = new WishAddActivityProtocol.Request();
        request.ˊ(str);
        if (i == 10) {
            request.ˏ("0");
        } else {
            request.ˏ("1");
        }
        wishAddActivityProtocol.ˎ(request);
        return new cjm("create.wish.activity", wishAddActivityProtocol);
    }
}
